package com.micro.Controller;
import com.api.net8.helloService;
import com.api.salary.SalaryClient;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.micro.domain.SysUser;
import com.micro.dto.UserDto;
import com.micro.service.ISysUserService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/user")
public class User {
    @Autowired
    public ISysUserService _isu;
    @Autowired
    private SalaryClient sas;

    @Autowired
    private helloService  hs;

    @GetMapping("/list")
    public Object list() {
        Object list = sas.list();
        System.out.println(list);
        return list;
    }
    @GetMapping("/list2")
    public Object list2() {

        for (int i = 0; i < 50; i++) {
            SysUser user = new SysUser();
            user.setUserName("Test"+i);
            user.setNickName("测试"+i);
            user.setDeptId((long) (i+1));
            _isu.saveOrUpdate(user);
        }
        return "数据初始化成功";
    }
    @GetMapping("/list3")
    public IPage<UserDto> list3() {
        Page<UserDto> page=new Page<>(1,10);
        return _isu.list3(page);
    }
    @GetMapping("/save")
    @GlobalTransactional
    public String SaveUser() {
        Long id = 2L;
        String Name = "若依2025_02_01更新过";
        var user = _isu.getBaseMapper().selectById(id);
        user.setNickName(Name);
        _isu.saveOrUpdate(user);
        //回写远程服务
        hs.UpdateS(id,Name);
        return "分布式事务更新数据成功";
    }
}
